﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Calendar;

namespace ClsController
{
    public partial class PopCalendar : Form
    {
        List<CalendarItem> items;

        public PopCalendar()
        {
            InitializeComponent();
            items = new List<CalendarItem>();
        }

        public void ClearCalendarItems()
        {
            items.Clear();
        }

        public void AddCalendarItems(DateTime tiempo, String nom, bool valorExiste)
        {
            if (valorExiste)
            {
                CalendarItem calitem = new CalendarItem(calDateCal, tiempo, TimeSpan.FromMinutes(30), nom + "-" + tiempo.ToShortDateString() + "-- FECHA COMPROMETIDA");
                calitem.BackgroundColor = Color.DarkRed;
                calitem.BackgroundColorLighter = Color.DarkMagenta;
                calitem.ForeColor = Color.White;
                items.Add(calitem);
            }
            else
            {
                items.Add(new CalendarItem(calDateCal, tiempo, TimeSpan.FromMinutes(30), nom + "-" + tiempo.ToShortDateString()));
            }
        }


        private void PopCalendar_Load(object sender, EventArgs e)
        {
            DateTime fehchaini = new DateTime();
            fehchaini = DateTime.Today.AddHours(8);
            calDateCal.SetViewRange(fehchaini, fehchaini);
            PlaceItems();
        }

        private void PlaceItems()
        {
            foreach (CalendarItem item in items)
            {
                if (calDateCal.ViewIntersects(item))
                {
                    calDateCal.Items.Add(item);
                }
            }
        }

        private void spltConentendorCal_SplitterMoved(object sender, SplitterEventArgs e)
        {
        }

        private void monthView1_SelectionChanged(object sender, EventArgs e)
        {
            calDateCal.SetViewRange(monthSelector.SelectionStart, monthSelector.SelectionEnd);
            PlaceItems();
        }

        private void calDateCal_ItemCreated(object sender, CalendarItemCancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void calDateCal_ItemCreating(object sender, CalendarItemCancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void calDateCal_ItemDeleting(object sender, CalendarItemCancelEventArgs e)
        {
            e.Cancel = true;
        }

        private void calDateCal_ItemsPositioned(object sender, EventArgs e)
        {}
    }
}
